home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / DATABASE / OBJ1_2.ZIP;1 / C_STACK.PRG < prev    next >
Encoding:
Text File  |  1993-01-21  |  2.2 KB  |  83 lines

  1. //*****************************************************************************
  2. // C_Stack.prg
  3. // Stack class for OBJECT v2.03
  4. // Copyright (c) 1991, JHK, JHK-Software, Piestany
  5. // Please compile with: /N/M/W/A
  6. //-----------------------------------------------------------------------------
  7.  
  8. #include "Object.ch"
  9.  
  10. create class Stack
  11.   export:
  12.   var Data    // {}
  13.   method New=StackNew              //o:New()
  14.   method Init=StackInit            //o:Init()
  15.   method Push=StackPush            //o:Push(val)
  16.   method Pop=StackPop              //o:Pop()
  17.   method Top=StackTop              //o:Top()
  18.   method IsEmpty=StackIsEmpty      //o:IsEmpty()
  19.   method Done=StackDone            //o:Done()
  20.   endclass
  21.  
  22.  
  23. //*****************************************************************************
  24. // Stack:New() --> self
  25. // initialize new object
  26. //
  27. constructor StackNew()
  28.   ::Data:= {}
  29.   return(self)
  30.  
  31.  
  32. //*****************************************************************************
  33. // Stack:Init() --> true
  34. // clear (make empty) the stack.
  35. //
  36. method function StackInit()
  37.   ::Data:={}
  38.   return(true)
  39.  
  40.  
  41. //*****************************************************************************
  42. // Stack:Push(xVal) --> xVal
  43. // push new value into stack.
  44. //
  45. method function StackPush(xVal)
  46.   AAdd(::Data,xVal)
  47.   return(xVal)
  48.  
  49.  
  50. //*****************************************************************************
  51. // Stack:Pop() --> xVal
  52. // take last entered value from stack.
  53. //
  54. method function StackPop()
  55.   return(ATailDel(::Data))
  56.  
  57.  
  58. //*****************************************************************************
  59. // Stack:Top() --> xVal
  60. // get last entered value from stack, do not erased it from stack.
  61. //
  62. method function StackTop()
  63.   return(ATail(::Data))
  64.  
  65.  
  66. //*****************************************************************************
  67. // Stack:IsEmpty() --> true/false
  68. // return true if the stack is empty.
  69. //
  70. method function StackIsEmpty()
  71.   return(Empty(::Data))
  72.  
  73.  
  74. //*****************************************************************************
  75. // Stack:Done() --> true
  76. // destroy the stack.
  77. //
  78. method function StackDone()
  79.   return(true)
  80.  
  81. //------------------------------------------------------- eof (c)JHK ----------
  82.  
  83.